package com.wsc.wisdomchina.activitity.minemodule;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.JsonTools;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.activitity.baseactivity.BaseActivity;
import com.wsc.wisdomchina.callback.ContributorView;
import com.wsc.wisdomchina.javaBean.BaiXingJianDuDetailBean;
import com.wsc.wisdomchina.javaBean.RespObj;
import com.wsc.wisdomchina.presenter.ContributorPresenter;
import com.wsc.wisdomchina.view.MyToast;

public class BaiXingDetailActivity extends BaseActivity implements ContributorView,View.OnClickListener {

    private ImageView  activity_wdfk_bxjdxq_imageOne, activity_wdfk_bxjdxq_imageTwo,
            activity_wdfk_bxjdxq_imageThree,regist_back;
    private TextView activity_wdfk_bxjdxq_slove, activity_wdfk_bxjdxq_time, activity_wdfk_bxjdxq_type,
            activity_wdfk_bxjdxq_name, activity_wdfk_bxjdxq_address, activity_wdfk_bxjdxq_title,
            activity_wdfk_bxjdxq_content,tv_headtitle;

    private LinearLayout activity_wdfk_bxjdxq_LLTI;

    private ContributorPresenter contributorPresenter;
    private Context context;
    private final String DETAILFLAG=BaiXingDetailActivity.class.getSimpleName();
    private final String DELETEHOUSEDELETEFLAG="DELETEHOUSEDELETEFLAG";
    private TextView tv_clear;
    private String previousId="";
    private MyToast myToast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.baixingjiandudetail_layout);
        initView();
        context=this;
        myToast=new MyToast(context);
        contributorPresenter = new ContributorPresenter(this, context);
        previousId=getIntent().getStringExtra("id");
        contributorPresenter.getBaiXingJianDuDetail(previousId,DETAILFLAG);
    }

    private void initView() {
        activity_wdfk_bxjdxq_imageOne = (ImageView) findViewById(R.id.activity_wdfk_bxjdxq_imageOne);
        activity_wdfk_bxjdxq_imageTwo = (ImageView) findViewById(R.id.activity_wdfk_bxjdxq_imageTwo);
        activity_wdfk_bxjdxq_imageThree = (ImageView) findViewById(R.id.activity_wdfk_bxjdxq_imageThree);
        activity_wdfk_bxjdxq_slove = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_slove);
        activity_wdfk_bxjdxq_time = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_time);
        activity_wdfk_bxjdxq_type = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_type);
        activity_wdfk_bxjdxq_name = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_name);
        activity_wdfk_bxjdxq_address = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_address);
        activity_wdfk_bxjdxq_title = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_title);
        activity_wdfk_bxjdxq_content = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_content);
        activity_wdfk_bxjdxq_LLTI= (LinearLayout) findViewById(R.id.activity_wdfk_bxjdxq_LLTI);
        regist_back=(ImageView) findViewById(R.id.regist_back);
        regist_back.setOnClickListener(this);
        tv_headtitle=(TextView) findViewById(R.id.tv_headtitle);
        tv_headtitle.setText("百姓监督");
        tv_clear=(TextView) findViewById(R.id.tv_clear);
        tv_clear.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.regist_back:
                finish();
                break;
            case R.id.tv_clear:
                contributorPresenter.getLightHouseDelete(previousId,DELETEHOUSEDELETEFLAG);
                break;
        }
    }

    @Override
    public void onLoadContributorStart(String flag) {

    }


    @Override
    public void onLoadContributorSuccess(String jsonString, String flag) {
        try {
            if(flag.equals(DELETEHOUSEDELETEFLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = (String) object;
                    if(jsonMessage.equals("41"))
                    {
                        myToast.showShort("删除成功");
                        Intent intent=getIntent();
                        setResult(1,intent);
                        finish();
                    }
                }else
                {
                    myToast.showShort("删除失败");
                }
            }else if (flag.equals(DETAILFLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = JsonTools.objectToJsonString(object);
                    BaiXingJianDuDetailBean sheQingDetailBean = JsonTools.jsonStringToObject(jsonMessage, BaiXingJianDuDetailBean.class);
                    if (sheQingDetailBean != null) {

                        if (sheQingDetailBean.getState() == 3) {
                            activity_wdfk_bxjdxq_slove.setText("未解决");
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.parseColor("#E9411E"));
                            tv_clear.setVisibility(View.VISIBLE);
                        } else if (sheQingDetailBean.getState() == 0) {
                            activity_wdfk_bxjdxq_slove.setText("处理中");
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.parseColor("#15CD1F"));
                            tv_clear.setVisibility(View.INVISIBLE);
                        } else if (sheQingDetailBean.getState() == 1) {
                            activity_wdfk_bxjdxq_slove.setText("处理中");
                            tv_clear.setVisibility(View.INVISIBLE);
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.parseColor("#15CD1F"));
                        } else if (sheQingDetailBean.getState() == 2) {
                            activity_wdfk_bxjdxq_slove.setText("已解决");
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.parseColor("#1ED4E9"));
                            tv_clear.setVisibility(View.INVISIBLE);
                        }

                        String date_time = Tools.timedate(String.valueOf(sheQingDetailBean.getCreateDate() / 1000));
                        activity_wdfk_bxjdxq_time.setText(date_time);
                        activity_wdfk_bxjdxq_type.setText(sheQingDetailBean.getType());
                        activity_wdfk_bxjdxq_name.setText(sheQingDetailBean.getReleaseName());
                        activity_wdfk_bxjdxq_address.setText(sheQingDetailBean.getAddr());
                        activity_wdfk_bxjdxq_title.setText(sheQingDetailBean.getTitle());
                        activity_wdfk_bxjdxq_content.setText(sheQingDetailBean.getContent());


                        if (sheQingDetailBean.getBanners().size() == 0) {
                            activity_wdfk_bxjdxq_LLTI.setVisibility(View.GONE);
                        } else if (sheQingDetailBean.getBanners().size() == 1) {
                            activity_wdfk_bxjdxq_LLTI.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageOne.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageTwo.setVisibility(View.INVISIBLE);
                            activity_wdfk_bxjdxq_imageThree.setVisibility(View.INVISIBLE);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(0)).into(activity_wdfk_bxjdxq_imageOne);
                        } else if (sheQingDetailBean.getBanners().size() == 2) {
                            activity_wdfk_bxjdxq_LLTI.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageOne.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageTwo.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageThree.setVisibility(View.INVISIBLE);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(0)).into(activity_wdfk_bxjdxq_imageOne);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(1)).into(activity_wdfk_bxjdxq_imageTwo);
                        } else if (sheQingDetailBean.getBanners().size() >= 3) {
                            activity_wdfk_bxjdxq_LLTI.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageOne.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageTwo.setVisibility(View.VISIBLE);
                            activity_wdfk_bxjdxq_imageThree.setVisibility(View.VISIBLE);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(0)).into(activity_wdfk_bxjdxq_imageOne);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(1)).into(activity_wdfk_bxjdxq_imageTwo);
                            Glide.with(this).load(sheQingDetailBean.getBanners().get(2)).into(activity_wdfk_bxjdxq_imageThree);
                        }
                    }

                }
            }

        } catch (Exception e) {

        }
    }


    @Override
    public void onLoadContributorComplete(String flag) {
    }

    @Override
    public void onLoadContributorError(String error, String flag) {
    }

}
